iT邦幫忙

2024 iThome 鐵人賽

DAY 12
0
Odoo

前後端整合學習,不只是後端管理系列 第 12

【Day12】 撰寫自己的模板 - 創建 Odoo 主題網站的 Content

  • 分享至 

  • xImage
  •  

加入 content

在第二篇中,我們會繼續擴展這個主題,並添加頁面的 content 部分。

資料夾結構更新

https://ithelp.ithome.com.tw/upload/images/20240920/2016548770AO2s15ak.png

1. 更新 __manifest__.py

我們需要在模組中新增 content.xml

{
    'name': 'My Custom Theme',
    'description': 'Custom theme for website with custom header.',
    'version': '1.0',
    'category': 'Theme/Website',
    'depends': ['website'],  # 依賴網站模組
    'data': [
        'views/layout.xml',  # 繼承 layout 視圖
        'views/header.xml',  # 自定義的 header 視圖
        'views/content.xml',  # 加載頁面主體內容
    ],
    'installable': True,
    'application': False,
}

2.定義 content.xml

這是頁面的 content 部分,顯示主體內容。我們會將 headercontent 一起渲染

<odoo>
    <template id="content">
        <section id="wrap" class="oe_structure">
            <div class="container">
                <h1>Welcome to My Website</h1>
                <p>This is the content section where you can introduce your products or services.</p>
            </div>
        </section>
    </template>
</odoo>

並依照上一篇的步驟,去安裝addons,切換到website頁面去編輯,更新自己的主題,如果發現主體報錯,建議可以先移除後重新於安裝主題的地方重新切換,這樣odoo會自動幫你安裝主題並安裝相對應的模組

成果應該會如下,你會發現header和content都被我們換掉了,剩下footer
https://ithelp.ithome.com.tw/upload/images/20240920/20165487oOPeiy5ghe.png

參考

Github


上一篇
【Day11】 撰寫自己的模板 - 創建 Odoo 主題網站的 header
下一篇
【Day13】 撰寫自己的模板 - 創建 Odoo 主題網站的 footer
系列文
前後端整合學習,不只是後端管理19
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言